package ysq.xyg.recovery.controller;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.recovery.model.po.RecoverySackRecord;
import ysq.xyg.recovery.model.vo.RecoverySackRecordVo;
import ysq.xyg.recovery.service.RecoverySackRecordService;
import ysq.xyg.web.model.po.WebMember;
import ysq.xyg.web.service.WebMemberService;

import javax.servlet.http.HttpServletRequest;

/**
 * 回收金模块-袋子记录表controller层
 *
 * @author congcong tao
 * @date 2019-7-8 14:46:54
 */
@RestController
public class RecoverySackRecordController extends BaseController {

    private static Logger log = LoggerFactory.getLogger(RecoverySackRecordController.class);

    @Autowired
    private WebMemberService webMemberService;
    @Autowired
    private RecoverySackRecordService recoverySackRecordService;

    private RecoverySackRecord recoverySackRecord;

    /**
     * 分页查询
     *
     * @param recoverySackRecordVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author congcong tao
     * @date 2019-7-8 14:46:54
     */
    @BaseLog(module = "回收金模块",className = "袋子记录表",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoverySackRecord/page",method = RequestMethod.POST)
    public ReturnEntity page(RecoverySackRecordVo recoverySackRecordVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = recoverySackRecordService.pageLeft(recoverySackRecordVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-7-8 14:46:54
     */
    @RequestMapping(value = "/recoverySackRecord/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/recovery/recoverySackRecordUpdateOrSave");
        if (StrUtil.isNotEmpty(id)) {
            recoverySackRecord = recoverySackRecordService.selectByPrimaryKey(id);
            view.addObject("recoverySackRecord", recoverySackRecord);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-7-8 14:46:54
     */
    @BaseLog(module = "回收金模块",className = "袋子记录表",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoverySackRecord/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return recoverySackRecordService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param recoverySackRecordVo Vo对象
     * @author congcong tao
     * @date 2019-7-8 14:46:54
     */
    @BaseLog(module = "回收金模块",className = "袋子记录表",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoverySackRecord/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,RecoverySackRecordVo recoverySackRecordVo){
        return recoverySackRecordService.addOrUpdate(recoverySackRecordVo,acceptCurrentUser(request));
    }

    /**
     * 完成盘点
     * @param id
     * @author congcong tao
     * @date 2019/7/9 10:27
     */
    @RequestMapping(value = "/recoverySackRecord/completeSack")
    public ReturnEntity completeSack(String id){
        // 完成盘点
        return recoverySackRecordService.completeSack(id);
    }

    /**
     * 完成订单
     * @param id
     * @author congcong tao
     * @date 2019/8/6 16:57
     */
    @RequestMapping(value = "/recoverySackRecord/completeOrder")
    public ReturnEntity completeOrder(String id){
        // 完成订单
        return recoverySackRecordService.completeOrder(id);
    }

    /**
     * 设置回收人
     * @param id
     * @param memberCoverId
     * @author congcong tao
     * @date 2019/7/9 15:25
     */
    @RequestMapping(value = "/recoverySackRecord/coverMember", method = RequestMethod.POST)
    public ReturnEntity coverMember(String id, String memberCoverId){
        RecoverySackRecord sackRecord = new RecoverySackRecord();
        WebMember webMember = webMemberService.selectByPrimaryKey(memberCoverId);
        sackRecord.setId(id);
        sackRecord.setMemberCoverId(memberCoverId);
        sackRecord.setMemberPhone(webMember.getPhone());
        recoverySackRecordService.updateByPrimaryKeySelective(sackRecord);
        return new ReturnEntity();
    }
}